"""
urllib.request 一般简单请求足够使用
第三方库 requests 更强大
"""

from urllib import request,parse
import json

def get_post():
    gank_api_post = 'https://gank.io/api/v2/post/{post_id}'
    post_id = '5e78b2f65d7c47fe610b0029'
    req = request.Request(gank_api_post.format(post_id= post_id))
    with request.urlopen(req) as f:
        return json.loads(f.read().decode('utf-8'))



def get_demo_data(file_name):
    data = get_post()
    with open(file_name, mode='a', encoding='utf-8', newline='\n') as f:
        f.write(str(data['data']))


get_demo_data('mydata.txt')
